/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package KeyServer;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import mysql.MysqlHandler;

/**
 *
 * @author John
 */

/**
 * Handles client connection requests.
 */
public class TempPassHandler implements Runnable {

    String imei;
    int duration;

    public TempPassHandler(String imei, int duration) {

        this.imei= imei;
        this.duration = duration;

    }

    public void run() {

        
        try {
            Thread.sleep(duration * 60000);
        } catch (InterruptedException ex) {
            Logger.getLogger(TempPassHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        deleteTempPass(imei);
        
    }
    
    
    public void deleteTempPass(String imei) {
        
        try {
            MysqlHandler mysql = new MysqlHandler();
            
            mysql.createConnection();
            
            mysql.deleteTempPass(imei);
            
            mysql.closeConnection();
            
            
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(TempPassHandler.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(TempPassHandler.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        
    }
    

}
